import {
	ref
} from 'vue'

export let user = ref({
	phone: '',
	code: '',
	username: ""
})

export let toLogin = () => {

	wx.redirectTo({
		url: '/pages/login/login'
	})
}

export let register = () => {
	if (!user.value.phone || !user.value.code || !user.value.username) {
		uni.showToast({
			title: '参数不能为空',
			icon: 'error',
			duration: 2000
		});
		return
	}
	uniCloud.callFunction({
			name: 'user',
			data: {
				apiName: 'register',
				params: user.value
			}
		})
		.then(res => {
			console.log(res.result, '注册')
			if (!res.result.status) {
				uni.showToast({
					title: res.result.message,
					icon: 'error',
					duration: 2000
				});
				return
			}
			uni.showToast({
				title: res.result.message,
				icon: 'success',
				duration: 2000
			});

		});
}